package com.usian.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.usian.fegin.UserFeign;
import com.usian.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {

    @Autowired
    private UserFeign userFeign;

    @RequestMapping("/findById/{id}")
    @SentinelResource(value = "/findById/{id}",
            //fallback = "test",
            blockHandler = "test1")
    public String findById(@PathVariable Integer id){
        int a = 100/0;
        //User user = userFeign.findById(id);
        //user.toString()
        return "111";
    }

    @RequestMapping("/test")
    public String test(Integer id){
        return "fallback 托底数据";  //托底  兜底
    }

    @RequestMapping("/test1")
    public String test1(Integer id,BlockException b){
        return "blockHander 托底数据"+b;  //托底  兜底
    }




    @RequestMapping("/findByName")
    @SentinelResource(value = "/findByName",fallback = "test")
    public User findByName(@RequestParam String name){
        User user = userFeign.findByName(name);
        return user;
    }


    @RequestMapping("/findByUser")
    public String findByUser(@RequestBody User user ){
        User user1 = userFeign.findByUser(user);
        return user1.toString();
    }




}
